package initialize

import (
	"fmt"
	"github.com/BurntSushi/toml"
)

type Config struct {
	Server  Server
	Mongodb Mongodb
	Jwt     Jwt
	Redis   Redis
}

type Captcha struct {
	KeyLong   int `yaml:"key-long"`
	ImgWidth  int `yaml:"img-width"`
	ImgHeight int `yaml:"img-height"`
}

type Redis struct {
	Ip       string
	Part     string
	Password string
	Database int64
}

type Mongodb struct {
	Ip       string
	Part     int64
	Database string
}

func (m *Mongodb) Link() string {
	return fmt.Sprintf("mongodb://%s:%d", m.Ip, m.Part)
}

type Server struct {
	Part   string // 地址
	Status string // 状态
}

//type FileConfig struct {
//	BasePath string `yaml:"basePath"` // 根路径
//}

type Jwt struct {
	SignKey     string `toml:"sign_key"`
	ExpiresTime int64  `toml:"expires_time"`
	Issuer      string
}

//type Logger struct {
//	Path string `yml:"path"` // 日志文件路径
//}

func InitConfig() Config {
	var config Config
	if _, err := toml.DecodeFile("config.toml", &config); err != nil {
		panic("config.toml配置文件读取失败:" + err.Error())
	}
	return config
}
